package com.canal.display.response;

import org.springframework.http.HttpStatus;

/**
 * @author Administrator
 * @description
 * @date 2019年03月16 12:49
 */
public class ResultUtil {

    private ResultUtil() {

    }

    /**
     * 创建成功返回
     * @return
     */
    public static Result makeSuccess() {
        return new Result().setCode(HttpStatus.OK.value())
                .setMessage("success");
    }

    /**
     * 创建成功
     * @param message
     * @return
     */
    public static Result makeSuccess(String message) {
        return new Result().setCode(HttpStatus.OK.value())
                .setMessage(message);
    }

    /**
     * 创建成功返回
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> makeSuccess(T data) {
        return new Result<T>()
                .setCode(HttpStatus.OK.value())
                .setMessage("success")
                .setData(data);
    }

    /**
     * 创建成功返回
     * @param message
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Result<T> makeSuccess(String message, T data) {
        return new Result<T>()
                .setCode(HttpStatus.OK.value())
                .setMessage(message)
                .setData(data);
    }

    /**
     * 创建失败返回
     * @param message
     * @return
     */
    public static Result makeFailure(String message) {
        return new Result()
                .setCode(HttpStatus.UNAUTHORIZED.value())
                .setMessage(message);
    }

    /**
     * 创建失败返回
     * @param code
     * @param message
     * @return
     */
    public static Result makeFailure(int code, String message) {
        return new Result()
                .setCode(code)
                .setMessage(message);
    }
}
